package com.linxz.ui.divider;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @author Linxz
 *         time:2018年06月30日 17:08.
 */

public class SpaceItemDecoration extends RecyclerView.ItemDecoration{

    public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
    public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
    private int mOrientation=HORIZONTAL_LIST;
    private int space;

    public SpaceItemDecoration(int space) {
        this.space = space;
    }

    public SpaceItemDecoration(int space,int orientation){
        this.space=space;
        this.mOrientation=orientation;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        if(parent.getChildPosition(view) != 0){
            if (mOrientation==HORIZONTAL_LIST){
                outRect.left=space;
            }else if (mOrientation==VERTICAL_LIST){
                outRect.top = space;
            }
        }

    }
}


